#include <iostream>
using namespace std;

// template<typename T>
struct Node
{
    Node* before;      //上一个元素的地址，首位为空
    Node* after;       //下一个元素的地址，最后为空
    int num;          //存储的值
};

class List
{
    private:
        Node* firstnode;
        Node* lastnode;
        int nums;
    public:
        List();
        void push_back(int a);
        void push_front(int a);
        void pop_back();
        void pop_front();
        Node* getnext(Node* p);
        Node* getfront(Node* p);
        Node* end(){return lastnode;}
        Node* first(){return firstnode;}

};

int main()
{
    List x;
    x.push_back(1);
    cout<<(x.end())->num;
}

List::List()
{
    firstnode->before=nullptr;
    lastnode->before=nullptr;
    nums=0;
}

void List::push_back(int a)
{
    Node* newnode=new Node;
    newnode->num=a;
    lastnode->after=newnode;
    lastnode=newnode;
    newnode->after=nullptr;
    nums++;
}

void List::push_front(int a)
{
    Node* newnode=new Node;
    newnode->num=a;
    firstnode->before=newnode;
    firstnode=newnode;
    newnode->before=nullptr;
    nums++;
}

void List::pop_back()
{
    Node* s=lastnode->before;
    delete lastnode;
    lastnode=s;
    s->after=nullptr;
}

void List::pop_front()
{
    Node* s=firstnode->after;
    delete firstnode;
    firstnode=s;
    s->before=nullptr;
}

Node* List::getnext(Node* p)
{
    if (p->after==nullptr)
    {
        printf("The node is the last node!");
        return p+1;
    }
    else
    {
        return p->after;
    }
}


Node* List::getfront(Node* p)
{
    if (p->before==nullptr)
    {
        printf("The node is the first node!");
        return p+1;
    }
    else
    {
        return p->before;
    }
}